package com.gt.modules.cent.controller;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.gt.annotation.DecryptId;
import com.gt.annotation.LogTag;
import com.gt.channel.ExchangeService;
import com.gt.contant.*;
import com.gt.entity.PActCentUser;
import com.gt.entity.TestVo;
import com.gt.entity.log.InterfaceLog;
import com.gt.mapper.InterfaceLogMapper;
import com.gt.mapper.PActCentUserMapper;
import com.gt.service.Log.InterfaceLogService;
import com.gt.service.impl.RedisHashService;
import com.gt.service.impl.RedisService;
import com.gt.service.impl.RedisZSetService;
import com.gt.threadlocal.RequestMapHolder;
import com.gt.utils.DatetimeUtil;
import com.gt.utils.RequestUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.data.redis.core.DefaultTypedTuple;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/*
 * @功能说明：测试demo
 * @作者： herun
 * @创建日期：2021/08/19
 * @版本号：V1.0
 */
@RestController
@RequestMapping("/demo")
@Slf4j
public class DemoController extends BaseController {
    @Resource
    private InterfaceLogService interfaceLogService;
    @Resource
    private InterfaceLogMapper interfaceLogMapper;
    @Resource
    private RedisService redisService;
    @Resource
    private ExchangeService exchangeService;
    @Resource
    PActCentUserMapper pActCentUserMapper;
    @Resource
    RedisZSetService redisZSetService;
    @Resource
    RedisHashService redisHashService;
    @LogTag(1)//增加日志监控，添加这个注解，默认会记录日志到数据库，2不记录到数据库
    @RequestMapping("/test")
//    @DecryptId
    @DecryptId(keyName = "wheelId")
    public Object test( @RequestBody  JSONObject reqJson) throws Exception {
        redisHashService.setCacheMap("leaderboard_map", JSONObject.parseObject(JSONUtil.toJsonStr(new TestVo().setName("wjh").setAge("11")), new TypeReference<Map<String, Object>>(){}));
        redisHashService.setCacheMapValue("leaderboard_map", "idCard",123);
        redisHashService.hIncrBy("leaderboard_map", "idCard", 1);
        log.info("info日志:{}",redisHashService.getCacheMap("leaderboard_map"));
//
//        return redisHashService.getCacheMap("leaderboard_map");
//        List<Object> multiCacheMapValue = redisHashService.getMultiCacheMapValue("leaderboard_map", Arrays.asList("age","idCard"));
        redisHashService.deleteCacheMapValue("leaderboard_map", "idCard");
        return DataResult.AJAX_OK;
    }
}